package com.atguigu.controller;

import com.atguigu.entity.Mail;
import com.atguigu.result.RetVal;
import com.atguigu.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * MailController
 *
 * @author yangchao
 * @version 开发阶段
 * @description TODO
 * @date 2022/3/14 11:41
 */
@RestController
@RequestMapping("/user")
public class MailController {
    @Autowired
    private MailService mailService;

    @RequestMapping(value = "/mailSend",method = RequestMethod.GET)
    public RetVal sendMail(@RequestParam(value = "email")String email){

        mailService.sendSimpleMail(email);
        return RetVal.ok();
    }

    @RequestMapping(value = "/verificationCode",method = RequestMethod.POST)
    public RetVal verificationCode(@RequestBody Mail mail){
        //验证 1 失败 2 成功
        if(StringUtils.isEmpty(mail.getMail())||StringUtils.isEmpty(mail.getCode())){
            return RetVal.ok(1);
        }
        Integer verifycode=mailService.verificationCode(mail);
        return RetVal.ok(verifycode);
    }
}

